package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Tv;
import com.ruoyi.system.service.ITvService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 节目类型Controller
 * 
 * @author saruri
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/tv")
public class TvController extends BaseController
{
    @Autowired
    private ITvService tvService;

    /**
     * 查询节目类型列表
     */
    @RequiresPermissions("system:tv:list")
    @GetMapping("/list")
    public TableDataInfo list(Tv tv)
    {
        startPage();
        List<Tv> list = tvService.selectTvList(tv);
        return getDataTable(list);
    }

    /**
     * 查询启用的节目类型列表，带排序
     */
    @RequiresPermissions("system:tv:list")
    @GetMapping("/enabledList")
    public TableDataInfo enabledList(Tv tv, String orderBy, String orderDirection, Integer isEnable) {

        if (isEnable != null) {
            tv.setIsEnable(isEnable);
        }
        startPage();
        List<Tv> list = tvService.selectEnabledTvList(tv, orderBy, orderDirection);
        return getDataTable(list);
    }

    /**
     * 导出节目类型列表
     */
    @RequiresPermissions("system:tv:export")
    @Log(title = "节目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tv tv)
    {
        List<Tv> list = tvService.selectTvList(tv);
        ExcelUtil<Tv> util = new ExcelUtil<Tv>(Tv.class);
        util.exportExcel(response, list, "节目类型数据");
    }

    /**
     * 获取节目类型详细信息
     */
    @RequiresPermissions("system:tv:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tvService.selectTvById(id));
    }

    /**
     * 新增节目类型
     */
    @RequiresPermissions("system:tv:add")
    @Log(title = "节目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tv tv)
    {
        return toAjax(tvService.insertTv(tv));
    }

    /**
     * 修改节目类型
     */
    @RequiresPermissions("system:tv:edit")
    @Log(title = "节目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tv tv)
    {
        return toAjax(tvService.updateTv(tv));
    }

    /**
     * 删除节目类型
     */
    @RequiresPermissions("system:tv:remove")
    @Log(title = "节目类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tvService.deleteTvByIds(ids));
    }
}
